<template>
  <aside>
    <el-menu :default-active="iframeActive||$route.path" class="menu-list" @open="handleopen" @close="handleclose" @select="handleselect"
             theme="dark" unique-opened router>
      <template v-for="(item,index) in menu_routers"  v-if="!item.hidden">
        <el-submenu :index="index+''" v-if="!item.leaf&&item.isFront==0" :key="index">
          <template slot="title"><i :class="item.iconCls"></i>{{item.name}}</template>
          <template v-for="(child,indexs) in item.children">
            <el-menu-item index="" :key="indexs" v-if="child.isFront==0&&child.path.indexOf('http')>-1" @click="iframeGo(child)">{{child.name}}</el-menu-item>
            <el-menu-item  :key="indexs" :index="child.path" v-else-if="child.isFront==0">{{child.name}}</el-menu-item>
          </template>
        </el-submenu>
        <el-menu-item index="" v-else-if="item.leaf&&item.isFront==0&&item.children.length>0&&item.children[0].path.indexOf('http')>-1" @click="iframeGo(item)" ><i :class="item.iconCls"></i>{{item.children[0].name}}</el-menu-item>
        <el-menu-item v-else-if="item.isFront==0&&item.leaf&&item.children.length>0" :index="item.children[0].path"><i :class="item.iconCls"></i>{{item.children[0].name}}</el-menu-item>
      </template>
    </el-menu>
  </aside>
</template>

<script>
  import { mapGetters } from 'vuex';
  export default {
		data() {
			return {
			}
		},
    computed: {
      ...mapGetters([
        'menu_routers',
        'iframeActive'
      ])
    },
		methods: {
			onSubmit() {
				console.log('submit!');
      },
      iframeGo(val){
        console.log(val)
        let pathData={}
        if(val.children.length){
          pathData.name=val.children[0].name
          pathData.src=val.children[0].path
        }else{
          pathData.name=val.name
          pathData.src=val.path
        }
        pathData.path='iframe'+val.id;
        this.$store.dispatch('toggleIframe',pathData);
        // this.$store.dispatch('addVisitedViews',pathData)
        this.$store.dispatch('addIframe', pathData)
        
      },
			handleopen() {
				console.log('handleopen');
			},
			handleclose() {
				//console.log('handleclose');
			},
			handleselect: function (indexPath) {
        this.$store.dispatch('toggleIframe');
        this.$store.dispatch('getOperation',indexPath).then(data=>{

        })
			},
		},
		created() {
		}
	}

</script>
<style>
</style>
